/*
 * ULSF Sagittarius IDA 
 * Copyright (C) 2012, John Pritchard, all rights reserved.
 * 
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */
package sagittarius.airfoil;

import sagittarius.Visualization;

import fv3.font.GlyphVector;
import fv3.math.VertexArray;

import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.VertexAttribute;

/**
 * Iterate over the chord of an airfoil geometry.
 *
 * The chord iteration operates on both edge cases uniformly.  In the
 * airfoil geometry vertex set, the first edge case has two identical
 * points.  That is, the first and last vertices in the vertex set
 * have identical values.  The interior edge case has one shared
 * midpoint.  The chord iteration, however, treats the first and
 * interior edge cases as having only one vertex.
 * 
 * @see ChordVertex
 * @see AirfoilVertices
 */
public final class ChordIterator
    extends MathAbstract
    implements Cloneable,
               java.lang.Iterable<ChordVertex>,
               java.util.Iterator<ChordVertex>
{


    public final AirfoilVertices airfoil;

    public final int length;

    private final float[] source;

    private ChordVertex[] target;

    private int index;


    public ChordIterator(AirfoilVertices airfoil, float[] list){
        super();
        this.airfoil = airfoil;
        if (null == list){
            this.source = null;
            this.target = null;
            this.length = 0;
        }
        else {
            this.source = list.clone();
            this.length = (airfoil.ne+1);
            this.target = new ChordVertex[this.length];
        }
    }



    public void reset(){

        this.index = 0;
    }
    public ChordVertex peek(int idx){
        if (-1 < idx && idx < this.length){
            ChordVertex cv = this.target[idx];
            if (null == cv){
                cv = new ChordVertex(this,this.source,idx);
                this.target[idx] = cv;
            }
            return cv;
        }
        else
            return null;
    }
    public java.util.Iterator<ChordVertex> iterator(){
        return this;
    }
    public boolean hasNext(){

        return (this.index < this.length);
    }
    public ChordVertex peek(){

        if (this.index < this.length){

            return this.peek(this.index);
        }
        else
            throw new java.util.NoSuchElementException();
    }
    public ChordVertex next(){

        if (this.index < this.length){

            return this.peek(this.index++);
        }
        else
            throw new java.util.NoSuchElementException();
    }
    public void remove(){
        throw new UnsupportedOperationException();
    }
    public void destroy(){

        this.target = null;
    }
    public void destroy(int idx){
        if (-1 < idx && idx < this.length)

            this.target[idx] = null;
        else
            throw new java.util.NoSuchElementException(String.valueOf(idx));
    }
}
